const staffService = require('../service/staff.service')

class StaffController {

  async create(ctx, next) {
    const woker = ctx.request.body;
    const { id } = ctx.user;
    const wokerObj = {
      ...woker,
      creator_id: id
    }
    const result = await staffService.create(wokerObj)

    ctx.body = {
      code: 0,
      message: '创建师傅成功 ~',
      data: result
    }
  }

  async findWokers(ctx, next) {
    let { limit, offset } = ctx.query
    if (!limit) limit = 10
    if (!offset) offset = 0
    const result = await staffService.findWokers(limit, offset)
    ctx.body = {
      code: 0,
      message: '获取师傅列表成功 ~',
      data: result
    }
  }

  async update(ctx, next) {
    const woker = ctx.request.body
    const result = await staffService.update(woker)
    ctx.body = {
      code: 0,
      message: '修改师傅信息成功 ~',
      data: result
    }
  }

  async delete(ctx, next) {
    const { id } = ctx.params
    const result = await staffService.delete(id)
    ctx.body = {
      code: 0,
      message: '删除师傅成功 ~',
      data: result
    }
  }
}

module.exports = new StaffController();